package prickworlds.graphics;

import java.util.ArrayList;

import prickworlds.structure.Drawable;

public abstract class ParticleEffect implements Drawable {
	ArrayList<Particle> particles;

	public ParticleEffect() {
		particles = new ArrayList<Particle>();
	}

	public void addParticle(Particle p) {
		particles.add(p);
	}

	@Override
	public void update() {
		for (int i = 0; i < particles.size(); i++) {
			Particle particle = particles.get(i);
			particle.update();
			if (particle.isFinished()) {
				particles.remove(i);
				i--;
				continue;
			}
		}
	}

	@Override
	public void display() {
		for (int i = 0; i < particles.size(); i++) {
			Particle particle = particles.get(i);
			particle.display();
		}
	}

	public boolean isFinished() {
		return particles.isEmpty();
	}
}
